//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "MultiProductOneStep.h"
using namespace Cephei::QL::Models::Marketmodels::Products;
#include <gen/QL/Models/Marketmodels/EvolutionDescription.h>
#include <gen/QL/Models/Marketmodels/CurveState.h>
#include <gen/QL/Models/Marketmodels/MarketModelMultiProductCashFlow.h>
#include <gen/QL/Models/Marketmodels/MarketModelMultiProduct.h>
using namespace Cephei::QL::Models::Marketmodels;
#undef HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Models::Marketmodels::Products::CMultiProductOneStep::CMultiProductOneStep (boost::shared_ptr<QuantLib::MultiProductOneStep>& childNative, Object^ owner) : CMarketModelMultiProduct(CMultiProductOneStep::typeid)
{
#ifdef HANDLE
	_phMultiProductOneStep = NULL;
#endif
	_ppMultiProductOneStep = &childNative;
    _ppMarketModelMultiProduct = new boost::shared_ptr<QuantLib::MarketModelMultiProduct> (boost::dynamic_pointer_cast<QuantLib::MarketModelMultiProduct> (*_ppMultiProductOneStep));
}
Cephei::QL::Models::Marketmodels::Products::CMultiProductOneStep::CMultiProductOneStep (QuantLib::MultiProductOneStep& childNative, Object^ owner) : CMarketModelMultiProduct(CMultiProductOneStep::typeid)
{
#ifdef HANDLE
	_phMultiProductOneStep = NULL;
#endif
	_ppMultiProductOneStep = new boost::shared_ptr<QuantLib::MultiProductOneStep> (&childNative);
    _ppMarketModelMultiProduct = new boost::shared_ptr<QuantLib::MarketModelMultiProduct> (boost::dynamic_pointer_cast<QuantLib::MarketModelMultiProduct> (*_ppMultiProductOneStep));
    _MultiProductOneStepOwner = owner;
    _MarketModelMultiProductOwner = owner;
}

Cephei::QL::Models::Marketmodels::Products::CMultiProductOneStep::CMultiProductOneStep (CMultiProductOneStep^ copy) : CMarketModelMultiProduct(CMultiProductOneStep::typeid)
{
#ifdef HANDLE
	_phMultiProductOneStep = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppMultiProductOneStep = new boost::shared_ptr<QuantLib::MultiProductOneStep> (copy->GetShared());
        _ppMarketModelMultiProduct = new boost::shared_ptr<QuantLib::MarketModelMultiProduct> (boost::dynamic_pointer_cast<QuantLib::MarketModelMultiProduct> (*_ppMultiProductOneStep));
    }
}
Cephei::QL::Models::Marketmodels::Products::CMultiProductOneStep::CMultiProductOneStep (System::Type^ t) : CMarketModelMultiProduct(CMultiProductOneStep::typeid)
{
#ifdef HANDLE
	_phMultiProductOneStep = NULL;
#endif
	if (!t->IsSubclassOf(CMultiProductOneStep::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Models::Marketmodels::Products::CMultiProductOneStep::CMultiProductOneStep (QuantLib::Handle<QuantLib::MultiProductOneStep>& childNative, Object^ owner)  : CMarketModelMultiProduct(CMultiProductOneStep::typeid)
{
	_phMultiProductOneStep = &childNative;
	_ppMultiProductOneStep = &static_cast<boost::shared_ptr<QuantLib::MultiProductOneStep>>(childNative.currentLink());
    _ppMarketModelMultiProduct = new boost::shared_ptr<QuantLib::MarketModelMultiProduct> (boost::dynamic_pointer_cast<QuantLib::MarketModelMultiProduct> (*_ppMultiProductOneStep));
    _MultiProductOneStepOwner = owner;
}
Cephei::QL::Models::Marketmodels::Products::CMultiProductOneStep::CMultiProductOneStep (QuantLib::Handle<QuantLib::MultiProductOneStep> childNative)  : CMarketModelMultiProduct(CMultiProductOneStep::typeid)
{
	_phMultiProductOneStep = &childNative;
	_ppMultiProductOneStep = &static_cast<boost::shared_ptr<QuantLib::MultiProductOneStep>>(childNative.currentLink());
    _ppMarketModelMultiProduct = new boost::shared_ptr<QuantLib::MarketModelMultiProduct> (boost::dynamic_pointer_cast<QuantLib::MarketModelMultiProduct> (*_ppMultiProductOneStep));
}
#endif
#ifdef STRUCT
Cephei::QL::Models::Marketmodels::Products::CMultiProductOneStep::CMultiProductOneStep (QuantLib::MultiProductOneStep childNative)  : CMarketModelMultiProduct(CMultiProductOneStep::typeid)
{
#ifdef HANDLE
	_phMultiProductOneStep = NULL;
#endif
	_ppMultiProductOneStep = new boost::shared_ptr<QuantLib::MultiProductOneStep> (new QuantLib::MultiProductOneStep (childNative));
    _ppMarketModelMultiProduct = new boost::shared_ptr<QuantLib::MarketModelMultiProduct> (boost::dynamic_pointer_cast<QuantLib::MarketModelMultiProduct> (*_ppMultiProductOneStep));
}
#endif

Cephei::QL::Models::Marketmodels::Products::CMultiProductOneStep::~CMultiProductOneStep ()
{
    if (_ppMultiProductOneStep != NULL)
    {
	    delete _ppMultiProductOneStep;
        _ppMultiProductOneStep = NULL;
    }
}
Cephei::QL::Models::Marketmodels::Products::CMultiProductOneStep::!CMultiProductOneStep ()
{
    if (_ppMultiProductOneStep != NULL)
    {
	    delete _ppMultiProductOneStep;
    }
}
QuantLib::MultiProductOneStep& Cephei::QL::Models::Marketmodels::Products::CMultiProductOneStep::GetReference ()
{
    if (_ppMultiProductOneStep == NULL) throw gcnew NativeNullException ();
	return **_ppMultiProductOneStep;
}
boost::shared_ptr<QuantLib::MultiProductOneStep>& Cephei::QL::Models::Marketmodels::Products::CMultiProductOneStep::GetShared ()
{
    if (_ppMultiProductOneStep == NULL) throw gcnew NativeNullException ();
	return *_ppMultiProductOneStep;
}
QuantLib::MultiProductOneStep* Cephei::QL::Models::Marketmodels::Products::CMultiProductOneStep::GetPointer ()
{
    if (_ppMultiProductOneStep == NULL) throw gcnew NativeNullException ();
	return &**_ppMultiProductOneStep;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::MultiProductOneStep>& Cephei::QL::Models::Marketmodels::Products::CMultiProductOneStep::GetHandle ()
{
	if (_phMultiProductOneStep == NULL)
	{
		_phMultiProductOneStep = new Handle<QuantLib::MultiProductOneStep> (*_ppMultiProductOneStep);
	}
	return *_phMultiProductOneStep;
}
#endif
bool Cephei::QL::Models::Marketmodels::Products::CMultiProductOneStep::HasNative () 
{
	return (_ppMultiProductOneStep != NULL);
}

Cephei::QL::Models::Marketmodels::IEvolutionDescription^ Cephei::QL::Models::Marketmodels::Products::CMultiProductOneStep::Evolution::get ()
{
    try
    {
    	QuantLib::EvolutionDescription& _rv = (QuantLib::EvolutionDescription&)(*_ppMultiProductOneStep)->evolution ( );   
        Cephei::QL::Models::Marketmodels::CEvolutionDescription^ _nrv = gcnew Cephei::QL::Models::Marketmodels::CEvolutionDescription (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::IVector<UInt64>^ Cephei::QL::Models::Marketmodels::Products::CMultiProductOneStep::SuggestedNumeraires::get ()
{
    try
    {
    	std::vector<QuantLib::Size> _rv = (std::vector<QuantLib::Size>)(*_ppMultiProductOneStep)->suggestedNumeraires ( );   
        Cephei::IVector<UInt64>^ _nrv = gcnew CoVector<UInt64> (gcnew CUInt64Vector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

